package com.ruoyi.system.service.project.impl;

import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.project.training.TrainingInfo;
import com.ruoyi.system.mapper.project.TrainingInfoMapper;
import com.ruoyi.system.service.project.ITrainingInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import static com.ruoyi.common.utils.SecurityUtils.getUserId;

/**
 * 研修培训Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-10-09
 */
@Service
public class TrainingInfoServiceImpl implements ITrainingInfoService
{
    @Autowired
    private TrainingInfoMapper trainingInfoMapper;

    /**
     * 查询研修培训
     * 
     * @param id 研修培训主键
     * @return 研修培训
     */
    @Override
    public TrainingInfo selectTrainingInfoById(Long id)
    {
        return trainingInfoMapper.selectTrainingInfoById(id);
    }

    /**
     * 查询研修培训列表
     * 
     * @param trainingInfo 研修培训
     * @return 研修培训
     */
    @Override
    public List<TrainingInfo> selectTrainingInfoList(TrainingInfo trainingInfo)
    {
        //如果是老师，则只显示自己上传的
        if(trainingInfo.getCurrentRole()!=null&&trainingInfo.getCurrentRole().equals("teacher")){
            trainingInfo.setReporterId(getUserId());
        }
        //如果是部门，则显示老师是系里的所有
        if(trainingInfo.getCurrentRole()!=null&&trainingInfo.getCurrentRole().equals("department")){
            trainingInfo.setDeptId(SecurityUtils.getDeptId());
        }
        return trainingInfoMapper.selectTrainingInfoList(trainingInfo);
    }

    /**
     * 新增研修培训
     * 
     * @param trainingInfo 研修培训
     * @return 结果
     */
    @Override
    public int insertTrainingInfo(TrainingInfo trainingInfo)
    {
        return trainingInfoMapper.insertTrainingInfo(trainingInfo);
    }

    /**
     * 修改研修培训
     * 
     * @param trainingInfo 研修培训
     * @return 结果
     */
    @Override
    public int updateTrainingInfo(TrainingInfo trainingInfo)
    {
        return trainingInfoMapper.updateTrainingInfo(trainingInfo);
    }

    /**
     * 批量删除研修培训
     * 
     * @param ids 需要删除的研修培训主键
     * @return 结果
     */
    @Override
    public int deleteTrainingInfoByIds(Long[] ids)
    {
        return trainingInfoMapper.deleteTrainingInfoByIds(ids);
    }

    /**
     * 删除研修培训信息
     * 
     * @param id 研修培训主键
     * @return 结果
     */
    @Override
    public int deleteTrainingInfoById(Long id)
    {
        return trainingInfoMapper.deleteTrainingInfoById(id);
    }
}
